<?php 
	$this->display(tpl('head',true)); 
	$display[$edit['ad_type']]=" style='display: block'";
	$checked[$edit['ad_type']]="checked";
?>
<!--<?php
if(!$edit[id]){
	$display['text']=" style='display: block'";
	$checked['text']="checked";
}
echo <<<php
-->
<style>
	.list{
		display: none;
	}
	.layui-input-block p{
		margin-top: 10px;
		color: #aaa;
	}
</style>
<script src="/Public/global/js/colpick.js" type="text/javascript" charset="utf-8"></script>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>创建/修改广告</legend>
</fieldset>
<form class="layui-form" method="post" action="">
	<div class="layui-form-item">
		<label class="layui-form-label">广告位名称</label>
		<div class="layui-input-block">
			<input name="post[name]" class="layui-input" type="text" value="$edit[name]">
			<p>作为相关文章的索引,如多个用空格隔开</p>
		</div>
	</div>
	<div class="layui-form-item">
		<label class="layui-form-label">广告位属性</label>
		<div class="layui-input-block">
			<input name="post[ad_type]" lay-filter="ad_type" class="layui-input" type="radio" value="text" title="文字广告位" {$checked['text']}>
			<input name="post[ad_type]" lay-filter="ad_type" class="layui-input" type="radio" value="images" title="图片广告位"	{$checked['images']}>
			<input name="post[ad_type]" lay-filter="ad_type" class="layui-input" type="radio" value="code" title="代码广告位"	{$checked['code']}>
		</div>
	</div>
	<div class="list text"{$display['text']}>
		<div class="layui-form-item">
			<label class="layui-form-label">文字内容</label>
			<div class="layui-input-block">
				<input name="post[text][title]" class="layui-input" type="text" value="{$setting['text']['title']}">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">文字链接地址</label>
			<div class="layui-input-block">
				<input name="post[text][weburl]" class="layui-input" type="text" value="{$setting['text']['weburl']}">
			</div>
		</div>
	</div>
	<div class="list code"{$display['code']}>
		<div class="layui-form-item">
			<label class="layui-form-label">代码内容</label>
			<div class="layui-input-block">
				<textarea  name='post[code]' id="code" style="width: 100%; height: 200px;">{$setting['code']}</textarea>
				<script type='text/javascript'>
				var ue = UE.getEditor('code', {
					zIndex: 900,
					toolbars: [
    ['fullscreen', 'source', 'undo', 'redo','bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc']
]
				});
			</script>
			</div>
		</div>
	</div>
	<div class="list images"{$display['images']}>
		<div class="layui-form-item">
			<label class="layui-form-label">图片地址</label>
			<div class="layui-input-block">
				<input name="post[images][imgurl]"  value="{$setting['images']['imgurl']}" id="img_url" class="layui-input" type="text" style="width: 50%;float: left;">
				<button style="float: left; margin-left: 50px;" type="button" class="layui-btn layui-btn-normal" id="select_img">选择图片上传</button>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">图片链接地址</label>
			<div class="layui-input-block">
				<input name="post[images][weburl]" value="{$setting['images']['weburl']}" class="layui-input" type="text">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">图片宽度</label>
			<div class="layui-input-block">
				<input name="post[images][width]" value="{$setting['images']['width']}" class="layui-input" type="text">
				<p>可以是100%，或者100px.像素单位必须填写</p>
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">图片高度</label>
			<div class="layui-input-block">
				<input name="post[images][height]" value="{$setting['images']['height']}" class="layui-input" type="text">
			</div>
		</div>
	</div>
	<div class="layui-form-item">
		<div class="layui-input-block my_button">
			<input type="hidden" name="id" value="$edit[id]" />
			<input type="hidden" name="step" value="post" />
			<button class="layui-btn" lay-submit="" lay-filter="post">立即提交</button>
		</div>
	</div>
</form>
<script>

layui.config({
	version: '$NOWTIME'
});
layui.use(['upload','form'], function(){
  	var $ = layui.jquery
  	,upload = layui.upload;
	var form = layui.form;
	form.on('radio(ad_type)', function(data){
		if(data.value=='text'){
			$(".text").show(500);
			$(".images").hide(500);
			$(".code").hide(500);
		}else if(data.value=='code'){
			$(".text").hide(500);
			$(".images").hide(500);
			$(".code").show(500);
		}else{
			$(".text").hide(500);
			$(".code").hide(500);
			$(".images").show(500);
		}
	});

	
	//选完文件后不自动上传
	upload.render({
	    elem: '#select_img',
	    url: '/admin/upfile/up',
	    auto: true,
	    before: function(obj){
	    	files = obj.pushFile(); //将每次选择的文件追加到文件队列
	    	loading = layer.load();
	    },
	    done: function(res, index, upload){
	    	layer.close(loading);
		    if(res.Result==0){
		    	layer.msg(res.content);
		    }else{
		      	$('#img_url').val(res.url); 
		    }
		    delete files[index]; //删除对应的文件
	    }
	});
});
	  
</script>
<!--
php;
?>-->
<?php 
$this->display(tpl('foot',true)); 
?>
